package com.beixiaohai.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.beixiaohai.service.RibbonService;

@RestController
public class RibbonController {
	
	@Autowired
	private RibbonService ribbonService;
	
	@Autowired
	private LoadBalancerClient loadBalancerClient;
	
	@GetMapping("hi")
	public String hi(@RequestParam(required=false,defaultValue="forezp")String name) {
		return ribbonService.hi(name);
	}
	
	@GetMapping("testRibbon")
	public String testRibbon() {
		ServiceInstance serviceInstance = loadBalancerClient.choose("beixiaohai-eureka-client");
		return serviceInstance.getHost() + ":" + serviceInstance.getPort();
	}
 
}
